package com.lxd.kyvideo.config;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration //相当于applicationContext.xml文件
@EnableOpenApi
public class Swagger3Config {

    @Value("${swagger3.enabled}")
    private Boolean swaggerEnabled;

    /**
     * 配置后端API接口摘要
     * @return
     */
    @Bean
    public Docket backendDocket(){
        return new Docket(DocumentationType.OAS_30)
                .groupName("管理端")
                .enable(swaggerEnabled) // 为了安全，在生产环境设置为false
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.lxd.kyvideo.controller.backend"))
                .paths(PathSelectors.any())
                .build();
    }


    /**
     * 配置前端API接口摘要
     * @return
     */
    @Bean
    public Docket frontendDocket(){
        return new Docket(DocumentationType.OAS_30)
                .groupName("小程序端")
                .enable(swaggerEnabled) // 为了安全，在生产环境设置为false
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.lxd.kyvideo.controller.frontend"))
                .paths(PathSelectors.any())
                .build();
    }


    /**
     * 配置接口文档API信息
     * @return
     */
    public ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("科云视频库接口文档")
                .description("科云视频库在线接口文档")
                .contact(new Contact("大牛", "http://localhost:8080/doc.html#", "290982492@qq.com"))
                .version("1.0")
                .build();
    }



}
